<script type="text/javascript">
    function exportCSVUserData()
    {
        var url = "?action=exportcsvuser";
        window.open(url, '_blank');
        window.focus();
    }
</script>
<div class="row-fluid no-margin">
    <div class="span12">
        <ul class="quicktasks">
            <?php if($view->can_create_user){ ?>
            <li>
                <a href="?action=createnewuser"> <img
                        src="<?php echo $view->layoutUrl; ?>assets/img/icons/essen/32/hire-me.png"
                        alt=""> <span>Add user</span>
                </a>
            </li>
            <?php } ?>
            <li>
                    <a href="javascript:exportCSVUserData();"> <img
                                    src="<?php echo $view->layoutUrl;?>assets/img/icons/essen/32/billing.png"
                                    alt=""> <span>Export to CSV</span>
                    </a>
            </li>
        </ul>
    </div>
</div>
<div class="row-fluid">
    <div class="span12">
        <div class="box">
            <div class="box-head">
                    <h3>Manage users</h3>
            </div>
            <div class="box-content box-nomargin">
                <?php if(isset($_GET['issuccess'])){?>
                <div class="alert alert-info">
                    Data saved succsesfully
                </div>
                <?php } ?>
                <table
                    class='table table-striped table-media table-bordered<?php if ($view->total <= 2000) { ?> dataTable<?php } ?>'>
                    <thead>
                        <tr>
                            <th>UID</th>
                            <th>Username</th>
                            <th>Email</th>
                            <th>Group</th>
                            <th>Created by</th>
                            <th>Is Active</th>
                            <th style="width: 190px;">Action</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach ($view->users as $i => $u) { ?>
                            <tr<?php if ($i % 2 != 0) { ?> style='background-color:#F6F6F6;'<?php } ?>>
                                <td><?php echo $u['user_id']; ?></td>
                                <td>
                                    <?php echo $u['username']; ?>
                                </td>
                                <td>
                                    <?php echo $u['email']; ?>
                                </td>
                                <td>
                                    <?php echo $view->config['groups'][$u['group_id']]; ?>
                                </td>
                                <td>
                                    <?php echo $view->saleUsers[$u['created_by_id']]['username']; ?>
                                </td>
                                <td>
                                    <center>
                                        <a href="?action=userlevel&user_id=<?php echo $u['user_id']; ?>" class='tip' title="Edit user access level">
                                            <?php if($u['is_disabled'] == 1){ ?>
                                            <span style="color:red;">No</span>
                                            <?php } else{ ?>
                                            <span style="color:green;font-weight: bolder;">Yes</span>
                                            <?php } ?>
                                        </a>
                                    </center>
                                </td>
                                <td class='actions_big'>
                                        <div class="btn-group">
                                            <a href="?action=userlevel&user_id=<?php echo $u['user_id']; ?>" class='btn btn-mini tip' title="Edit user access level">
                                                <img src="<?php echo $view->layoutUrl; ?>assets/img/icons/fugue/key-solid.png" alt="">
                                            </a>
                                            
                                            <?php if($view->can_create_user){ ?>
                                            <a href="?action=createnewuser&user_id=<?php echo $u['user_id']; ?>" class='btn btn-mini tip' title="Edit">
                                                <img src="<?php echo $view->layoutUrl; ?>assets/img/icons/essen/16/edit.png" alt="">
                                            </a>
                                            <?php } ?>
                                            <?php if($view->can_delete_user){ ?>
                                            <a confirm="Are you sure to remove this user?" href="?action=userdelete&user_id=<?php echo $u['user_id']; ?>" class='btn btn-mini tip confirm' title="Remove">
                                                    <img src="<?php echo $view->layoutUrl; ?>assets/img/icons/fugue/cross.png" alt="">
                                            </a>
                                            <?php } ?>
                                            <?php if($view->can_login_as_user){ ?>
                                            <a href="?action=loginasuser&user_id=<?php echo $u['user_id']; ?>" class='btn btn-mini tip' title="Login as user">
                                                    <img src="<?php echo $view->layoutUrl; ?>assets/img/icons/fugue/navigation.png" alt="">
                                            </a>
                                            <?php } ?>
                                            <?php if($u['group_id'] == 2) { ?>
                                            <a href="?action=userpermission&user_id=<?php echo $u['user_id']; ?>" class='btn btn-mini tip' title="Edit user permission">
                                                    <img src="<?php echo $view->layoutUrl; ?>assets/img/icons/fugue/wrench-screwdriver.png" alt="">
                                            </a>
                                            <?php } ?>
                                            <?php if($view->user['group_id'] == 1) { ?>
                                            <a href="?action=userinvoice&user_id=<?php echo $u['user_id']; ?>" class='btn btn-mini tip' title="User invoices">
                                                    <img src="<?php echo $view->layoutUrl; ?>assets/img/icons/fugue/inbox-document.png" alt="">
                                            </a>
                                            <?php } ?>
                                        </div>
                                </td>
                            </tr>
                        <?php } ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
</div>
</div>